package com.dolphin.servicemap.remot;

import com.dolphin.common.constant.AmapConfigConstants;
import com.dolphin.common.dto.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@Slf4j
public class MapDicDistrictClient {
    @Value("${amap.key}")
    private String amapKey;

    @Autowired
    RestTemplate restTemplate;
    public String dicDistrict(String keywords){
        //https://restapi.amap.com/v3/config/district?keywords=北京&subdistrict=2&key=2eaf6eb9ba18dce6f8076479f9a39f4c
        //拼装url
        StringBuilder url = new StringBuilder();
        url.append(AmapConfigConstants.DISTRICT_URL)
                .append("?")
                .append("keywords="+keywords)
                .append("&")
                .append("subdistrict=3")
                .append("&")
                .append("key="+amapKey);
        //解析结果
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);


        //插入数据库

        return forEntity.getBody();
    }
}
